<?php
include_package( 'Xml' );

class XmlDatabaseForeignKeyElement extends XmlElement {

	function XmlDatabaseForeignKeyElement( &$oConfiguration, &$oForeignKey ) {

		$this->XmlElement( 'foreignKey' );
		$this->AddAttribute( 'name'     , $oForeignKey->GetName() );
		$this->AddAttribute( 'id'       , $oForeignKey->GetName() );
		$this->AddAttribute( 'fromTable', $oForeignKey->GetFromTableName() );
		$this->AddAttribute( 'toTable'  , $oForeignKey->GetToTableName() );
		$this->AddAttribute( 'mandatory', $oForeignKey->IsMandatory() ? 'true' : 'false' );
		
		if ( $oConfiguration->GetProperty( 'ShowForeignKeyColumns' ) ) {
	
			foreach( $oForeignKey->GetColumnNames() as $iSequence => $sThisColumn ) {
				$oForeignKeyColumn = new XmlElement( 'foreignKeyColumn' );
				$oForeignKeyColumn->AddAttribute( 'columnId' , $oForeignKey->GetFromTableName() . '.' . $sThisColumn );
				$oForeignKeyColumn->AddAttribute( 'sequence' , $iSequence );
				$this->AddElement( $oForeignKeyColumn );
			}
		}
	}
}

require_once( 'XmlDatabaseColumnElement.php' );
	
?>
